/**
 * 
 */
package vn.nt.healthcare.server.ws.orm.hibernate;

import java.io.Serializable;

import org.hibernate.dialect.Dialect;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.PrimitiveType;
import org.hibernate.type.StringType;
import org.hibernate.type.descriptor.sql.CharTypeDescriptor;

/**
 * @author Huy
 * 
 */
@SuppressWarnings("serial")
public class LowerCaseYesNoType extends
		AbstractSingleColumnStandardBasicType<Boolean> implements
		PrimitiveType<Boolean>, DiscriminatorType<Boolean> {

	public static final LowerCaseYesNoType INSTANCE = new LowerCaseYesNoType();

	public LowerCaseYesNoType() {
		super(CharTypeDescriptor.INSTANCE, MyBooleanTypeDescriptor.INSTANCE);
	}

	public String getName() {
		return "yes_no";
	}

	public Class getPrimitiveClass() {
		return boolean.class;
	}

	public Boolean stringToObject(String xml) throws Exception {
		return fromString(xml);
	}

	public Serializable getDefaultValue() {
		return Boolean.FALSE;
	}

	@SuppressWarnings({ "UnnecessaryUnboxing" })
	public String objectToSQLString(Boolean value, Dialect dialect)
			throws Exception {
		return StringType.INSTANCE.objectToSQLString(value.booleanValue() ? "y"
				: "n", dialect);
	}
}

